package com.fuxue.service.impl;

import com.fuxue.dto.CommitDTO;
import com.fuxue.dto.GetCommitDTO;
import com.fuxue.entity.Commit;
import com.fuxue.mapper.CommitMapper;
import com.fuxue.result.PageResult;
import com.fuxue.service.CommitService;
import com.fuxue.vo.ForumVO;


import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.time.LocalDateTime;
import java.util.List;

@Service
public class CommitServiceImpl implements CommitService {
       @Autowired
       private CommitMapper commitMapper;

       /*
       添加评论
        */
       @Override
       @Transactional
       public void InsertCommit(CommitDTO commitDTO) {
              commitDTO.setCreatTime(LocalDateTime.now());
              commitMapper.InsertCommit(commitDTO);
              commitMapper.updateAnswerCount(commitDTO.getAnswerId());

       }

       @Override
       public PageResult pageQuery(GetCommitDTO getCommitDTO) {
              PageHelper.startPage(getCommitDTO.getPage(), getCommitDTO.getPageSize());
              Page<Commit> page = commitMapper.getAllCommit(getCommitDTO);
              long total = page.getTotal();

              List<Commit> records = page.getResult();
              return new PageResult(total, records);

       }
}
